package oldFiles;
import lejos.nxt.MotorPort;


public class TachoMeter
{	
	private int b_total_cnt = 0;
	private int c_total_cnt = 0;
	private int b_last = 0, c_last = 0;
	public void Update()
	{
		int b_cnt = MotorPort.B.getTachoCount();
		int c_cnt = MotorPort.C.getTachoCount();
		
		b_total_cnt = b_cnt;
		c_total_cnt = c_cnt;
		/*
		//b_cnt = b_cnt * -1;
		//c_cnt = c_cnt * -1;
		
		if( b_cnt >= b_last )
		{
			b_total_cnt += (b_cnt - b_last);
		}
		else
		{
			int rest = 360 - b_last;
			b_total_cnt += (b_cnt + rest);
		}
		
		if( c_cnt >= c_last )
		{
			c_total_cnt += (c_cnt - c_last);
		}
		else
		{
			int rest = 360 - c_last;
			c_total_cnt += (c_cnt + rest);
		}
		b_last = b_cnt;
		c_last = c_cnt;
		*/
	}

	public void Clear()
	{
		b_total_cnt = 0;
		c_total_cnt = 0;
		b_last = 0;
		c_last = 0;
		MotorPort.B.resetTachoCount();
		MotorPort.C.resetTachoCount();
	}
	
	public int getBCount()
	{
		return b_total_cnt;
	}
	
	public int getCCount()
	{
		return c_total_cnt;
	}
	
	public int GetDiff()
	{
		return b_total_cnt - c_total_cnt;
	}
}
